#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 27 14:20:44 2018
Plot combine
@author: zhuo

"""

import matplotlib.pyplot as plt
import numpy as np

def get_data(Nuclei,Type):
      #Nuclei = "O16"
      #Type = "IVD"
      path_1 = "../../data/nnlosat2b/"
      path_2 = "../../data/nnlosat2b_3b/"
      filename1 = path_1+Nuclei+"_sat2b_12_"+Type+end
      filename2 = path_2+Nuclei+"_"+Type+end
      data1 = [[],[]]
      data2 = [[],[]]
      with open(filename1) as f:
            for line in f.readlines()[1:]:
                  for each in enumerate(line.split()):
                        #print ("each[0]", each[0], "\t each[1]", each[1])
                        data1[each[0]].append(float(each[1]))
      x1,y1 = data1
      with open(filename2) as f:
            for line in f.readlines()[1:]:
                  for each in enumerate(line.split()):
                        #print ("each[0]", each[0], "\t each[1]", each[1])
                        data2[each[0]].append(float(each[1]))     
      x2,y2 = data2
      return x1,y1,x2,y2



Nuclei = "O16"
Type = "ISQ"

Nuclei_all_1 = ["He4","O16","Ca40"]
Nuclei_all_2 = ["O22","O24","Ca48"]
Nuclei_all = ["He4","O22","O16","O24","Ca40","Ca48"]

plt.figure()
plt.title(Type)
index = 0
for nuclei in Nuclei_all:
      x1,y1,x2,y2=get_data(nuclei,Type)

      y1_max = max(y1)
      y2_max = max(y2)
      y_max = max(y1_max,y2_max)
      ylim_max = y_max*1.1

      x1_max = max(x1)
      x2_max = max(x2)
      x_max = max(x1_max,x2_max)
      xlim_max = x_max*1
      index+=1
      plt.subplot(3,2,index)
      plt.plot(x1, y1, label='$nnlo_{sat}\quad 2N$')
      plt.plot(x2, y2, label='$nnlo_{sat}\quad 2N+3N$')
      plt.legend(loc='upper right', prop={'size': 4})

      plt.ylim(0,ylim_max)
      plt.xlim(0,xlim_max)
      plt.xlabel('$E[MeV]$',fontsize=8)
      plt.ylabel('$R$',fontsize=8)
      font_dict = {'family':'serif','color':'darkred','size':10}

      plt.text(0.8*x_max, 0.5*y_max,nuclei,fontdict=font_dict)
      #plt.text(0.8*x_max, 0.6*y_max,Type,fontdict=font_dict)


output=Type+".jpg"
plt.savefig(output,dpi = 200)
plt.show()


